From 2d11016ecd6adcf23dc187323d9e7a48a94988bd Mon Sep 17 00:00:00 2001 From: umherirrender Date: Tue, 6 May 2014 21:03:45 +0200 Subject: [PATCH] Pass $user to LocalFileDeleteBatch This avoids the use of $wgUser Change-Id: I60cab27e0708a818c77791cc89194b6dd726da0b --- includes/FileDeleteForm.php | 4 ++-- includes/filerepo/file/LocalFile.php | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 44aaeb4a6e..642c49e13e 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -149,7 +149,7 @@ class FileDeleteForm { if ( $oldimage ) { $page = null; - $status = $file->deleteOld( $oldimage, $reason, $suppress ); + $status = $file->deleteOld( $oldimage, $reason, $suppress, $user ); if ( $status->ok ) { // Need to do a log item $logComment = wfMessage( 'deletedrevision', $oldimage )->inContentLanguage()->text(); @@ -180,7 +180,7 @@ class FileDeleteForm { // doDeleteArticleReal() returns a non-fatal error status if the page // or revision is missing, so check for isOK() rather than isGood() if ( $deleteStatus->isOK() ) { - $status = $file->delete( $reason, $suppress ); + $status = $file->delete( $reason, $suppress, $user ); if ( $status->isOK() ) { $dbw->commit( __METHOD__ ); } else { diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index b3d5d5dc51..7fb85b9fb1 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1599,14 +1599,15 @@ class LocalFile extends File { * * @param string $reason * @param bool $suppress + * @param User|null $user * @return FileRepoStatus */ - function delete( $reason, $suppress = false ) { + function delete( $reason, $suppress = false, $user = null ) { if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); } - $batch = new LocalFileDeleteBatch( $this, $reason, $suppress ); + $batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user ); $this->lock(); // begin $batch->addCurrent(); @@ -1656,16 +1657,17 @@ class LocalFile extends File { * @param string $archiveName * @param string $reason * @param bool $suppress + * @param User|null $user * @throws MWException Exception on database or file store failure * @return FileRepoStatus */ - function deleteOld( $archiveName, $reason, $suppress = false ) { + function deleteOld( $archiveName, $reason, $suppress = false, $user = null ) { global $wgUseSquid; if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); } - $batch = new LocalFileDeleteBatch( $this, $reason, $suppress ); + $batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user ); $this->lock(); // begin $batch->addOld( $archiveName ); @@ -1964,15 +1966,25 @@ class LocalFileDeleteBatch { /** @var FileRepoStatus */ private $status; + /** @var User */ + private $user; + /** * @param File $file * @param string $reason * @param bool $suppress + * @param User|null $user */ - function __construct( File $file, $reason = '', $suppress = false ) { + function __construct( File $file, $reason = '', $suppress = false, $user = null ) { $this->file = $file; $this->reason = $reason; $this->suppress = $suppress; + if ( $user ) { + $this->user = $user; + } else { + global $wgUser; + $this->user = $wgUser; + } $this->status = $file->repo->newGood(); } @@ -2086,11 +2098,9 @@ class LocalFileDeleteBatch { } function doDBInserts() { - global $wgUser; - $dbw = $this->file->repo->getMasterDB(); $encTimestamp = $dbw->addQuotes( $dbw->timestamp() ); - $encUserId = $dbw->addQuotes( $wgUser->getId() ); + $encUserId = $dbw->addQuotes( $this->user->getId() ); $encReason = $dbw->addQuotes( $this->reason ); $encGroup = $dbw->addQuotes( 'deleted' ); $ext = $this->file->getExtension(); -- 2.20.1